home *** CD-ROM | disk | FTP | other *** search
- #ifndef OTPOLLENDPOINT_H
- #define OTPOLLENDPOINT_H
- /*------------------------------------------------------------------------------
- #
- # NewsTicker, my Hack for 1997
- #
- # OTPollEndPoint.cp - A general OT Endpoint class., designed to be derived.
- #
- # After you open the connection, calling its DoIdle routine will check for
- # any incoming data, and if found, call a derived method (broken into
- # lines, if desired). Also, when the connection is broken, it will call a
- # derived shutdown method.
- #
- # Not to be treated as a great example of OT programming, but it works.
- #
- ------------------------------------------------------------------------------*/
-
- //+++Inc - Includes for files not directly related to this project
- #include <OpenTransport.h>
- #include <OpenTptInternet.h>
- #include <Types.h>
-
- #define keOTPEPaborted -1
-
- //This is a "waiting" class
- class Idler;
-
- class OTPollEndPoint
- {
- protected:
- Boolean mfCancelled;
- Boolean mfDataWaiting;
- Boolean mfLostConnection;
- Boolean mfNeedsDisconnecting;
- Boolean mfDataInIsText;
-
- char mfInComingData[4096]; //data being received
- short mfBytesReceived;
-
-
- OTTimeout mulResolveTimeout;
- volatile EndpointRef mpEndpoint;
- MapperRef mpMapperRef;
-
- enum OutpointState { keBinding, keBindingDone,
- keConnecting, keConnectingDone,
- keDisconnecting, keDisconnectingDone,
- keOrderlyDisconnecting, keOrderlyDisconnectingDone,
-
- keOpeningMapper, keOpeningMapperDone,
- keResolving, keResolvingDone,
-
- keBailingOut };
-
- OSErr miAsyncErr;
- OutpointState meState;
- union {
- InetAddress inet;
- } mfDestAddress;
-
- protected:
- OTPollEndPoint (const OTPollEndPoint& oRHS);
- OTPollEndPoint& operator= (const OTPollEndPoint& oRHS);
-
- // Returns true if the endpoint has been cancelled. Also disconnects and destroys
- // the endpoint if it has been cancelled.
- Boolean CheckCancelled (Idler& oIdler);
-
- Boolean EndPointValid (void) const;
- OSErr DestroyEndPoint(void);
- void CheckOTError (OTResult lError);
-
- OSErr OpenEndpoint (const char *protocol);
- OSErr ResolveAddress (Idler& oIdler, const char* pszHost, InetHost& lHostsIPAddress);
-
- static pascal void Notifier (void* contextPtr, OTEventCode code,
- OTResult result, void* cookie);
- void HandleNotify (OTEventCode code, OTResult result, void* cookie);
-
- virtual OSErr GetData ( void );
- //
- // This is the workhorse
- //
- virtual void HandleData (char* thestring, short numchars);
- //
- // If we need to tell someone we've closed, override this
- //
- virtual void HandleShutdown (void);
-
- public:
- OTPollEndPoint (void);
- virtual ~OTPollEndPoint (void);
-
- OSErr Open (Idler& oIdler, const char *address, short port);
- OSErr Close (Idler* poIdler);
-
- void Cancel (void);
- void SetCancelFlag (Boolean fCancel) { mfCancelled = fCancel; }
-
- virtual OSErr SendData (Idler& oIdler, const void *pData, long lSize);
-
- virtual void DoIdle (void);
-
-
- };
-
- #endif //OTPollEndPoint_H
-